﻿//微信

var id;
if($.cookie("MYID")){id=$.cookie("MYID")};
var returnurl=encodeURIComponent("https://www.pulu.com/weixin/sendexp.html"); //同意后跳转页面
$(document).ready(function(){
    if(is_weixn()){
        if($.cookie("wxopenid")){
            //===============================================================================
            //从登录页返回有openid没有id
            if(!$.cookie("MYID")){location.href="https://www.pulu.com/weixin/login.html"}
            //===============================================================================
        }
        else{
            //先微信验证获取openid 如果已经授权过了 直接页面截取openid 然后发送请求获取 用户的ID
            var reg=new RegExp("code=[a-zA-Z0-9]*");
            if(window.location.href.match(reg)){
                var code=window.location.href.match(reg);
                $.ajax({
                    type:"GET",
                    url:"GetOpenId.ashx?"+code,
                    async: false,
                    success:function(data){
                        console.log(data);
                        var dat=data;
                        $.cookie("wxod",dat);
                        //发请求获取用户的id
                        $.ajax({
                            type:"GET",
                            url:getwxopenidurl+dat,
                            success:function(d){
                                //如果没有用户id 则证明用户是第一次登陆 保存openid跳转至登录页面
                                if(!d.Data){
                                    //微信跳转进来的
                                    if(!$.cookie("MYID")){
                                        $.cookie("wxopenid",dat);
                                        location.href="https://www.pulu.com/weixin/login.html";
                                    }
                                    //退出登录的
                                }else if(d.Data&&d.Data.userId.length>0){
                                    $.cookie("wxopenid",d.Data.openId);
                                    $.cookie("MYID",d.Data.userId);
                                    location.href="https://www.pulu.com/weixin/sendexp.html";
                                    //id=d.Data.userId;
                                }
                            }
                        })
                    }
                })
            }
            else{
                location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx658c34793ecfd9f9&redirect_uri="+returnurl+"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
            }
        }
    }
    //else{
    //    allftn();
    //}
});

$("#sendimginfo div").css("marginTop",(window.innerHeight-83)/2);
$("#sendinfo div").css("marginTop",(window.innerHeight-83)/2);
var divheight=parseFloat(window.innerWidth)*0.21;
var hyischoiced=[];//已经选择的行业document.body.clientWidth
var xqischoiced=[];//已经选择的兴趣
var question = {};
question.score =0;//分数
var qtypenum =3;

$(".queskind").html("经验");
$("#sendinfop").html("正在上传经验，请耐心等待..");
document.querySelector(".page_title.unified").innerHTML="分享经验";
document.querySelector(".navigation_button.sendquesbtn").innerHTML="发布";
//$("#keywordinput").attr("placeholder","关键词必填，且在文中出现过");
//原window.load内容
question.qtype=3;//2问题3经验
question.isstrangersee = 1;//陌生人是否可见  0否1是
question.ishidename = 0;//是否匿名发布  0否1是
atmeIsHideName=0;//默认不匿名
question.iswhocansee = 0;//是否是部分可见 0否1是 和 isforbidwhosee互斥
question.isforbidwhosee = 0;//是否是不给谁看  0否1是 和 iswhocansee互斥
var persons = [];  //招唤的人
var labeldata;//保存标签组
var woseetype="";//用来判断当前标签组是部分可见 还是提醒谁看
//------------------------------------------------------------------------------------------------------------------------
//监听输入框数字（纯一位数字）
$("#price").bind('input propertychange',function(){
    //包含其他字符
    if(!/^[0-9]+$/.test($("#price").val())){
        $("#price").val($("#price").val().replace(/[^0-9]/ig,""));
    }
    if($("#price").val()){
        var a=$("#price").val().toString();
        var b= a.substr(0,1);
        $("#price").val(parseFloat(b));
    }
});
//关闭alert提示----------------------------------------------
$("#closealertbtn").click(function(){
    $("#nokeywordalert").css("display","none");
});
//展示大图片------------------------------------------------
var winscrolltop;
var imghash={};//保存服务器返回的图片地址 “images.localId[i]”：imgurl
var delimgid="";//要删除的图片的Id
//展示大图
function showbigimg(e){
    winscrolltop=$(window).scrollTop();
    $("#page_wrapper").css("display","none");
    if(e.dataset.imgurl.match("Images/")){
        $("#showimg").attr("src",imgurl+e.dataset.img);//大图片的地址 和 Id 相同
    }else{
        $("#showimg").attr("src",imgurl+e.dataset.img);//大图片的地址 和 Id 相同
    }
    $("#digimgplace").css("display","block");
    var bigheight=$("#digimgplace").height();
    var imgheight=$("#showimg").height();
    if(bigheight>imgheight){
        $("#showimg").css("marginTop",(bigheight-imgheight)/2);
    }
    delimgid=e.dataset.img;//地址 和 Id 相同
}
//删除大图
$("#delthisimgbtn").click(function(e){
    imghash[delimgid]="";//清除对应ID 保存的服务器图片地址
    //页面中删掉图片
    var imgbox=document.getElementsByClassName("mainshowimgbox");
    for(var i= 0,r=imgbox.length;i<r;i++){
        if(imgbox[i].dataset.img==delimgid){
            //$imgbox=$(imgbox[i].dataset.img);
            $(".mainshowimgbox")[i].remove();
        }
    }
    $(".modifier.image").css("display","inlineBlock");
    $("#page_wrapper").css("display","block");
    $("#digimgplace").css("display","none");
});
$("#bigimgback").click(function(){
    $("#page_wrapper").css("display","block");
    $("#digimgplace").css("display","none");
})
//关闭地图区域
$("#digimgplace").click(function(e){
    if(e.id!="delthisimgbtn"){
        $("#page_wrapper").css("display","block");
        $("#digimgplace").css("display","none");
        if(winscrolltop>0){
            //console.log(winscrolltop);
            $(window).scrollTop(winscrolltop);
        }
    }
});
//微信部分==========================================
$.ajax({
    type:"GET",
    url:"GetSign.ashx?p=weixin/sendexp.html",
    success:function(data){
        timestampone=data.timestamp;
        nonceStrone=data.nonceStr;
        signatureone=data.signature;
        wx.config({
            debug:false,
            appId: 'wx658c34793ecfd9f9',
            timestamp:timestampone, //时间戳
            nonceStr:nonceStrone,  //随机字符串
            signature:signatureone,  //SHA1编码
            jsApiList: [
                // 所有要调用的 API 都要加到这个列表中
                "chooseImage","uploadImage","previewImage","downloadImage"
            ]
        });
    }
})
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////主页面操作////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var bodyplace=document.getElementsByClassName("bodyplace")[0];//主页面
var gaojilist=document.getElementsByClassName("gaojilist")[0];//高级页面
var inputbox1=document.querySelector("#inputbox1 div");//主页面确定按钮
var gjabtnok=document.querySelector("#gjabtnok");//高级页面确定按钮
var inputbox3=document.querySelector("#hyabtnok");//行业页面确定按钮
//点击后退
$("#maingobackbtn").click(function(){
    var conf=confirm("您的数据不会被保存，确定退出吗");
    if(conf===true){
        history.go(-1);
    }
});
//        输入框
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
function ResizeTextarea(a,row){
    if(!a){return}
    if(!row)
        row=5;
    var b=a.value.split("\n");
    var c=is_ie?1:0;
    c+=b.length;
    var d=a.cols;
    if(d<=20){d=40}
    for(var e=0;e<b.length;e++){
        if(b[e].length>=d){
            c+=Math.ceil(b[e].length/d)
        }
    }
    c=Math.max(c,row);
    if(c!=a.rows){
        a.rows=c;
    }
}
//        弹出设置价格
var sendquesbtn=document.getElementsByClassName("sendquesbtn")[0];//提交问题按钮
var tishiwords=document.getElementById("tishiwords");
var modalbg=document.getElementsByClassName("modal_bg")[0];
var modal=document.getElementsByClassName("action_menu_container")[0];
var cancel=document.getElementsByClassName("cancel");
var timer;
var keywordtitle="";//关键词生成的标题
function changeclass(){
    modalbg.className='modal_bg';
    modal.className='action_menu_container';
    clearTimeout();
    timer=null;
    changedisplay();
};
function changedisplay(){
    modalbg.style.display="none";
    modal.style.display="none";
};
// 完成按钮
sendquesbtn.onclick=function(){
    //经验要有关键词
    if($("#contentword").val().trim().length<10){
        alert("字数有点少，再加点吧，至少10字哦");
    }else{
        var keyword=document.getElementById("keywordinput").value;
        if(document.getElementById("keywordinput").value&&!document.getElementById("keywordinput").value.match(/^\s+$/g)){
            var outbox1=document.getElementById("outbox1");
            if(typeof window.getComputedStyle!='undefined'){
                //如果支持W3C，使用getComputedStyle来获取样式
                var hei=getComputedStyle(outbox1).height;
                modal.style.height=hei+"px";
            }else if(element.currentStyle){
                var hei=parseInt(outbox1.currentStyle[height]);
                modal.style.height=hei+"px";
            }
            modalbg.style.display="block";
            modal.style.display="block";
            $("#price").val(1);
            keywordtitle=document.getElementById("keywordinput").value;
        }else{
            $("#nokeywordalert").css("display","block");
        }
    }
};

//页面按钮控件
var imgbtn=document.querySelector(".modifier.image");//主页面图片按钮
var choiceimgplace=document.getElementsByClassName("choiceimgplace")[0];
var imgokbtn=document.querySelector(".imgokbtn");//图片页面确定按钮
var imgchoicefriend=document.getElementById("sd-imgchoicefriend");//图片选择好友区域
var hidename=document.getElementById("hidename");//陌生人不可见
var strangecansee=document.getElementById("strangecansee");//陌生人不可见
//问题相关按钮控件
var callfriend=$("#callfriend")[0];//提醒谁看
var imgs = [];//图片列表-------用于向服务器传递参数
//、、、、、、、、、、、、、、、、、、、、、、、、、、、、方法提前
//主页面添加图片-----------------------------------------
var height21=parseFloat(document.body.clientWidth)*0.21;
console.log(height21);
var urlfrom=location.href;
$("#questionbody .modifier").height(height21+"px");
//选择推荐城市-------------------------------------------
function getlocationhash(e){
    //------------------------------------------
    var name=lacationhash[e.id].name;
    $("#location div:nth-child(2)").html(lacationhash[e.id].name);
    $("#firstchoice .name").html(name);
    $("#firstchoice .dizhi").html(lacationhash[e.id].address);
    $("#firstchoice img").css("display","block");
    $("#firstchoice").css("display","block");
    //------------------------------------------
    $(".myctywords").html(lacationhash[e.id].name);
    $(".myctywords").css("display","none");
    $("#firstchoice").css("display","block");
    //alert(lacationhash[e.id].name);
    $("#firstchoice .name").html(lacationhash[e.id].name);
    $("#firstchoice .dizhi").html(lacationhash[e.id].address);
    $("#showmap").css("display","none");//页面
    $("#firstchoice img").css("display","block");
    $("#nolocation img").css("display","none");//钩
    $("#shiname img").css("display","none");
    //添加地址
    if(e.dataset.lng){
        question.longitude= e.dataset.lng;
        question.latitude=e.dataset.lat;
    }
}
var lacationhash={};//保存所有推荐定位的hash
var choicel=[];//已经选择的定位
//选择“不显示城市”------------------------------------
$("#nolocation").click(function(){
    //$("#location div:nth-child(2)").css("display","block");
    $("#location div:nth-child(2)").html("所在位置");
    $(".myctywords").css("display","none");
    $(".myctywords").html("");
    $("#firstchoice").css("display","none");
    //$("#firstchoice").html("");
    //choicel=null;
    $("#showmap").css("display","none");//页面
    $("#nolocation img").css("display","block");
    $("#firstchoice img").css("display","none");
    $("#shiname img").css("display","none");
});
//选择省份----------------------------------------------
var shengshi;//市
$("#shiname").click(function(e){
    $("#location div:nth-child(2)").html(shengshi);
    $("#firstchoice").css("display","none");
    $(".myctywords").html(shengshi);
    $(".myctywords").css("display","none");
    choicel=null;
    $("#showmap").css("display","none");//页面
    $("#nolocation img").css("display","none");//钩
    $("#firstchoice img").css("display","none");
    $("#shiname img").css("display","block");
});
//选地址返回-------------------------------------------
$("#mapgoback").click(function(){
    $("#showmap").css("display","none");//页面
});
//搜索城市----------------------------------------------
var pagenum=1;
function searchcity(pagenum){
    if($("#locationsearch input")[0].value){
        var searchword=$("#locationsearch input")[0].value;
        $("#nosearch").css("display","block");
        var map = new AMap.Map("mapplace", {
            resizeEnable: true
        });
        AMap.service(["AMap.PlaceSearch"], function() {
            var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
                pageSize: 20,
                pageIndex: pagenum,
                city: shengshi, //城市
                map: map
            });
            //关键字查询
            placeSearch.search(searchword,function(status, result){
                var data=result.poiList.pois;
                $(data).each(function(){
                    $("#searclocation").append("<div id="+$(this)[0].id+" onclick='getlocationhash(this)' data-lat='"+$(this)[0].location.lat+"' data-lng='"+$(this)[0].location.lng+"'>"+$(this)[0].name+"<div class='dizhi'>"+$(this)[0].address+"</div></div>");
                    if(!lacationhash[$(this)[0].id]){
                        lacationhash[$(this)[0].id]={"name":$(this)[0].name,"address":$(this)[0].address,"location":$(this)[0].location}
                    }
                });
                $("#locationlistplace").css("display","none");
                $("#otherlist").css("display","none");
                $("#searclocation").css("display","block");
            });
        });
    }
}
//取消搜索----------------------------------------------
$("#nosearch").click(function(){
    $("#searclocation div").remove();
    $("#nosearch").css("display","none");
    $("#locationlistplace").css("display","block");
    $("#otherlist").css("display","block");
    $("#searclocation").css("display","none");
});
//------------------------------------------------------
var pageindex=1;
var nowlocation;//当前位置
window.onload=function(){
    if(qtypenum){question.qtype=qtypenum};//2问题3经验
//加载好友列表----------------------------------------------
    //获得好友列表
    $.ajax({
        datatype:"json",
        type:"get",
        url:friendlisturl+id,
        success:function(d){
            console.log("好友列表");
            console.log(d);
            if(d.Data.length>0){
                //排序
                //friendarr= d.Data;
                friendarr= (d.Data).sort(compare);
                //function compare(property){
                //    return function(a,b){
                //        var value1 = pinyin.getCamelChars(a[property]);
                //        var value2 = pinyin.getCamelChars(b[property]);
                //        return value1.localeCompare(value2);
                //    }
                //}
                //friendarr.sort(compare("friendnick"));
                hasharr={};//判断字母是否存在
                for(var i=0;i<friendarr.length;i++){
                    if(friendarr[i].friendnick){
                        friendarr[this.index]=i;
                        //如果昵称开头为汉字或英文字母
                        var key=Pinyin.getCamelChars(friendarr[i].friendnick[0]);
                        var headimg="<img src='img/af8.png' class='topic_photo_img'/>"
                        if(friendarr[i].headimg){
                            headimg="<img src='http://42.62.66.198:8003/"+friendarr[i].headimg+"' class='topic_photo_img'/>";
                        }
                        if(key.match(/[a-z|A-Z]/)){
                            key=key.toLowerCase();
                            //console.log(key);
                            if(!hasharr[Pinyin.getCamelChars(friendarr[i].friendnick[0])]){
                                hasharr[Pinyin.getCamelChars(friendarr[i].friendnick[0])]=i;
                            }
                            $("#maina").append("<div class='section_header section_header_gray "+key+"' data-num='"+i+"' style='display:none'> <span class='"+key+"'>"+key+"</span> </div><div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
                            $("#aa").append("<div class='section_header section_header_gray "+key+"' data-num='"+i+"' style='display:none'> <span class='"+key+"'>"+key+"</span> </div><div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn' data-fid='"+friendarr[i].friendId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
                        }else{
                            $("#mainjinghao").css("display","block");
                            $("#mainjinghao").append("<div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
                            $("#jinghao").css("display","block");
                            $("#jinghao").append("<div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn' data-fid='"+friendarr[i].friendId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
                        };
                    }
                }
                //console.log(hasharr);
                for(var key in hasharr){
                    key=key.toLowerCase();
                    $("#sd-imgchoicefriend .section_header.section_header_gray."+key).eq(0).css("display","block");
                    $("#somesee .section_header.section_header_gray."+key).eq(0).css("display","block");

                    $("#imgchoicefriend .section_header.section_header_gray."+key).eq(0).css("display","block");
                    $("#somesee .section_header.section_header_gray."+key).eq(0).css("display","block");
                };
            }
        }
    });
    //右侧导航条点击跳转
    //字母键
    var englishbtn1=document.querySelectorAll(".rightnav1 div.zmbtn");//导航条跳转
    var tonum1=0;
    for(var en1=0;en1<englishbtn1.length;en1++){
        englishbtn1[en1].onclick=function(e){
            console.log("点击的是："+e.target.innerHTML);
            if(document.querySelector(".section_header.section_header_gray."+(e.target.innerHTML).toLowerCase())){
                console.log("进行跳转");
                var engtitlenum=parseFloat(hasharr[e.target.innerHTML]);
                var divnum=parseFloat(document.querySelector(".section_header.section_header_gray."+(e.target.innerHTML).toLowerCase()).dataset.num);
                var divheight=$(".friends").eq(0).height();
                var titleheight=$("div.section_header.section_header_gray").eq(0).height();
                heightdiv=titleheight*engtitlenum+divnum*divheight;
                $(window).scrollTop(0);
                $(window).scrollTop(heightdiv);
                console.log("页面跳转操作")
            }
        };
    }
//定位 城市-------------------------------------------------
    //周边推荐--------------------
    function otherlocal(position,shiname,pageindex){
        var map = new AMap.Map("mapplace", {
            resizeEnable: true
        });
        AMap.service(["AMap.PlaceSearch"], function() {
            var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
                pageSize: 20,
                pageIndex:pageindex,
                city: shiname, //城市
                map: map
                //panel: "otherlist"
            });
            var cpoint = position; //中心点坐标
            placeSearch.searchNearBy('', cpoint, 200, function(status, result) {
                var data=result.poiList.pois;
                $(data).each(function(){
                    $("#otherlist").append("<div id="+$(this)[0].id+" onclick='getlocationhash(this)' data-lat='"+$(this)[0].location.lat+"' data-lng='"+$(this)[0].location.lng+"'>"+$(this)[0].name+"<div class='dizhi'>"+$(this)[0].address+"</div></div>");
                    if(!lacationhash[$(this)[0].id]){
                        lacationhash[$(this)[0].id]={"name":$(this)[0].name,"address":$(this)[0].address,"location":$(this)[0].location}
                    }
                    //选择周边推荐----------------
                });

            });
        });
    }
    $("#location").click(function(){
        //高德地图--------------------------------------------------
        var map, geolocation;
//加载地图，调用浏览器定位服务
        map = new AMap.Map('mapplace', {
            resizeEnable: true
        });
        map.plugin('AMap.Geolocation', function() {
            geolocation = new AMap.Geolocation({
                enableHighAccuracy: true,//是否使用高精度定位，默认:true
                noIpLocate:0,
                GeoLocationFirst:true,//默认为false，设置为true的时候可以调整PC端为优先使用浏览器定位，失败后使用IP定位
                convert: true,         //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
                timeout: 100000,          //超过100秒后停止定位，默认：无穷大
                buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
                zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
                buttonPosition:'RB'
            });
            map.addControl(geolocation);
            geolocation.getCurrentPosition();
            AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
            AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
        });
//解析定位结果
        function onComplete(data) {
            var shiname=data.formattedAddress.split("省")[1].split("市")[0]+"市";
            shengshi=shiname;
            nowlocation=data.position;
            $("#shiname div").html(shiname);
            otherlocal(data.position,shiname,pageindex);
        }
//解析定位错误信息
        function onError(data) {
            //document.getElementById('tip').innerHTML = '定位失败';
        }
        $("#locationlistplace").css("display","block");//搜索影响
        $("#otherlist").css("display","block");
        $("#showmap").css("display","block");//展开页面
    });
    $("#showmap").scroll(function(){
        var mainheight=$(".home_feed").height();
        var windowheight=$(window).height();
        var chajuli=$(".home_feed").offset().top - $(window).scrollTop();
        var cz=windowheight-mainheight+5;
        //console.log();
        if(chajuli<cz){
            if($("#searclocation").css("display")==="none"){
                pageindex++;
                otherlocal(nowlocation,shengshi,pageindex);
            }
            else{
                pagenum++;
                searchcity(pagenum);
            }
        }
    });
//匿名发布--------------------------------------------------
    hidename.onclick=function(){
        if(question.ishidename ===0){
            question.ishidename = 1;
            atmeIsHideName=1;
            $("#hidename div.changephotobox img").attr("src","img/hook01.png")
        }else if(question.ishidename ===1){
            question.ishidename =0;
            atmeIsHideName=0;
            $("#hidename div.changephotobox img").attr("src","img/hook-no.png")
        }
    };
//陌生人不可见（问题经验）-----------------------------------
    strangecansee.onclick=function(){
        if(question.isstrangersee ===1){
            question.isstrangersee =0;
            $("#strangecansee div.changephotobox img").attr("src","img/hook01.png")
        }else if(question.isstrangersee ===0){
            question.isstrangersee =1;
            $("#strangecansee div.changephotobox img").attr("src","img/hook-no.png")
        }
    };
//上传图片--------------------------------------------------
    var images = {
        localId: [],
        serverId: []
    };
    var sendlocalIds;
    imgbtn.onclick=function(){
        //微信部分==========================================
        var imgnum=9;//选择图片个数
        if(document.getElementsByClassName("mainshowimgbox")&&document.getElementsByClassName("mainshowimgbox").length>0){
            imgnum=9-document.getElementsByClassName("mainshowimgbox").length;
        }
        wx.chooseImage({
            count: imgnum, // 默认9
            sizeType:['compressed'],
            success: function(res) {
                var cameraimg;
                images.localId = res.localIds;
                //alert("本地ID："+res.localIds);
                //如果只选了一张照片 看成拍照设置cameraimg
                if( res.localIds.length==1){
                    cameraimg= res.localIds;
                    //alert("拍照的图片地址："+cameraimg);
                }
                //alert('已选择 ' + res.localIds.length + ' 张图片');
                if (images.localId.length == 0) {
                    alert('请先使用 chooseImage 接口选择图片');
                    return;
                }else{
                    //如果不是拍照
                    //if(!cameraimg){
                    //    var divheight=parseFloat(window.innerWidth)*0.21;
                    //    for(var r=0;r<images.localId.length;r++){
                    //        $("<div class='mainshowimgbox' style='height:"+divheight+"px;overflow:hidden;' onclick='showbigimg(this)'  data-imgurl='"+images.localId[r]+"' data-img='"+images.localId[r]+"'><img src='"+images.localId[r]+"'></div>").insertBefore("#questionbody .modifier.image");
                    //    }
                    //}
                }
                var divheight=parseFloat(window.innerWidth)*0.21;
                var i = 0, length = images.localId.length;
                images.serverId = [];
                function upload(){
                    wx.uploadImage({
                        localId: images.localId[i],
                        isShowProgressTips: 0, // 默认为1，显示进度提示
                        success: function(res) {
                            var locaimgurl=images.localId[i];
                            i++;
                            images.serverId.push(res.serverId);

                            //请求服务器下载图片
                            $.ajax({
                                type:"get",
                                url:wxgetimgurl+res.serverId,
                                success:function(img){
                                    var imgurlword;
                                    imgurlword=img.replace("C:\\","");
                                    if(cameraimg&&cameraimg.length==1){ //只选了一张图片 看成拍照
                                        //$(".modifier.image").css("background","url('"+imgurl+imgurlword+"')");
                                        $("<div class='mainshowimgbox' style='height:"+divheight+"px;overflow:hidden;' onclick='showbigimg(this)' data-imgurl='"+cameraimg+"' data-img='"+imgurlword+"'><img src='"+cameraimg+"'></div>").insertBefore("#questionbody .modifier.image");
                                        imghash[res.serverId]=img.replace("C:\\","");
                                    }else{
                                        $("<div class='mainshowimgbox' style='height:"+divheight+"px;overflow:hidden;' onclick='showbigimg(this)' data-imgurl='"+cameraimg+"' data-img='"+imgurlword+"'><img src='"+images.localId[i-1]+"'></div>").insertBefore("#questionbody .modifier.image");
                                        imghash[images.localId[i]]=img.replace("C:\\","");
                                    }
                                    //判断图片个数 9个隐藏按钮
                                    if(document.getElementsByClassName("mainshowimgbox")&&document.getElementsByClassName("mainshowimgbox").length==9){
                                        $(".modifier.image").css("display","none");
                                    }
                                    //若果没上传好就继续
                                    if (i < length) {
                                        upload();
                                    }
                                }
                            });
                        },
                        fail: function(res) {
                            alert("图片上传失败了");
                            //alert(JSON.stringify(res));
                        }
                    });
                }
                upload();
            }
        });
    };
    $("#addimgfilebtn").height(($(window).width()-30)*0.23);
//金额加减按钮操作----------------------------------------
    //金额加减按钮操作
    $("#leftjianbtn").click(function(){
        var num=$("#price").val();
        num=parseFloat(num);
        if(!num||num<=1){
            $("#price").val(1);
            $("#leftjianbtn").css("backgroundImage","url('img/reduce_light.png')");
            $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
        }else{
            if(num===5){
                $("#price").val(1);
                $("#leftjianbtn").css("backgroundImage","url('img/reduce_light.png')");
                $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
            }else if(num>=9){
                $("#price").val(5);
                $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
            }else{
                --num;
                $("#price").val(num);
                $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')");
                $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
            }
        }
    });
    $("#rightjiabtn").click(function(){
        var num=$("#price").val();
        num=parseFloat(num);
        if(num>=9){
            $("#price").val("9");
            num=9;
            $("#rightjiabtn").css("backgroundImage","url('img/add_light.png')");
            $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')")
        }else{
            if(num===1||!num){
                $("#price").val("5");
                $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')")
            }else if(num===5){
                $("#price").val("9");
                $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')");
                $("#rightjiabtn").css("backgroundImage","url('img/add_light.png')")
            }else{
                ++num;
                $("#price").val(num);
                $("#leftjianbtn").css("backgroundImage","url('img/reduce_deep.png')");
                $("#rightjiabtn").css("backgroundImage","url('img/add_deep.png')")
            }
        }
    });
    //问题经验提醒谁看@
    callfriend.onclick=function(){
        bodyplace.style.display="none";
        imgchoicefriend.style.display="block";//与图片共用一个好友列表
        $(window).scrollTop(0);
        sendfriend=1;
        callfrienfname=[];
    };
    //提醒谁看
    imgchoicedFDokbtn.onclick=function(){
        imgchoicefriend.style.display="none";
        bodyplace.style.display="block";
        //console.log("提醒谁看方法");
        var choicefriendlist=$("#sd-imgchoicefriend .addchatpeoplebtn");//所有好友列表 单选按钮
        persons = [];
        for(var f=0;f<choicefriendlist.length;f++){
            //console.log("提醒谁看方法for循环");
            if(choicefriendlist[f].checked==true){
                persons.push(choicefriendlist[f].parentNode.id);
                var childlist=choicefriendlist[f].parentNode.childNodes;
                for(var i=0;i<childlist.length;i++){
                    if(childlist[i].className==="innerplace tc_text"){//wentibufen ///////////////////////////////
                        callfrienfname.push(childlist[i].innerHTML);
                        console.log(callfrienfname);
                    }
                }
            }
        }
        if($("#callfriendwords span")){
            $("#callfriendwords span").remove();
        }
        if(callfrienfname.length!=0){
            if(callfrienfname.length>3){
                $("#callfriendwords").append("<span>"+callfrienfname[0]+","+callfrienfname[1]+","+callfrienfname[2]+"等"+callfrienfname.length+"人"+"</span>")
            }else{
                for(var ii=0;ii<callfrienfname.length;ii++){
                    $("#callfriendwords").append("<span>"+callfrienfname[ii]+"</span>")
                }
            }
        }
    };
    //提醒谁看页面关闭
    $("#friendlistgoback").click(function(){
        $("#sd-imgchoicefriend").css("display","none");
        $("#page_wrapper").css("display","block");
    });
    //设置价格按钮进行提价操作    提交所有信息
    var sendbtn=document.getElementsByClassName("sendbtn")[0];
    sendbtn.onclick=function(){
        //最后操作获取其他参数 发送请求====================================================================
        //if(modalbg.style.display=="block"&&modal.style.display=="block"){
        if(modal.style.display=="block"){
            modalbg.className+=' animate_out';
            modal.className+=' animate_out';
        }
        timer=setTimeout(changeclass,100);

        //图片
        if(document.getElementsByClassName("mainshowimgbox")[0]){
            imgs = [];
            console.log("有图片",document.getElementsByClassName("mainshowimgbox"));
            //从数组中获取图片
            var imgbox=document.getElementsByClassName("mainshowimgbox");
            for(var i= 0,len=imgbox.length;i<len;i++){
                var img={};
                img.plist ="";
                if(!/Images\//.test(imgbox[i].dataset.img)){

                    img.name="Images/"+imgbox[i].dataset.img+".jpg";
                }else{
                    img.name=imgbox[i].dataset.img;
                }

                imgs.push(img);
            }
        }else{
            console.log("没有图");
            imgs="[]";
        }
        //问题或经验
        //标题问题
        question.content = document.getElementById("contentword").value;
        question.questionUserId = id;//发布人的id
        question.status ="1";
        if($(".myctywords span")){
            question.pululocation = $(".myctywords").html();
        }
        //console.log( question.score);
        //兴趣
        var hobbytypes = [];
        var userhobby=document.querySelectorAll(".kindword.xingquwords>span");
        if(userhobby){
            for(var h=0;h<userhobby.length;h++){
                var t={};
                t.id=userhobby[h].id;
                t.name=userhobby[h].innerHTML;
                hobbytypes.push(t);
            }
        }
        //行业
        var jobtypes = [];
        var userjob=document.querySelectorAll(".kindword.hangyewords>span");
        if(userjob){
            for(var j=0;j<userjob.length;j++){
                var t1={};
                t1.id=userjob[j].id;
                t1.name=userjob[j].innerHTML;
                jobtypes.push(t1);
            }
        }
        var sendcanseelist = [];//可见人的id列表
        if(question.iswhocansee ===1){
            var seelabellistimg=document.querySelectorAll("#someseelabel .labelbox .labellist .labelbtnimg");
            for(var ii=0;ii<seelabellistimg.length;ii++){
                if(seelabellistimg[ii].src.match("hook01")){
                    var num=seelabellistimg[ii].dataset.i;
                    for(var iii=0;iii<labeldata[num].userList.length;iii++ ){
                        sendcanseelist.push(labeldata[num].userList[iii].userId);
                    }
                }
            }
            //sendcanseelist=pwhocanseelist;
        }else if(question.isforbidwhosee ===1){
            var notlabellistimg=document.querySelectorAll("#cannotseelabel .labelbox .labellist .labelbtnimg");
            for(var rr=0;rr<notlabellistimg.length;rr++){
                if(notlabellistimg[rr].src.match("hook01")){
                    var num1=notlabellistimg[rr].dataset.i;
                    for(var rrr=0;rrr<labeldata[num1].userList.length;rrr++ ){
                        sendcanseelist.push(labeldata[num1].userList[rrr].userId)
                    }
                }
            }
            //sendcanseelist=pforbidseelist;
        }else if(question.iswhocansee ===0&&question.isforbidwhosee ===0){
            sendcanseelist=[];
        }
        //发送问题的关键字
        question.keywords=$("#keywordinput").val();
        console.log(sendcanseelist);
        var callerid="";
        if(persons.length>0){
            callerid=id;
        }
        //经验的金额
        if(document.getElementById("price").value&&qtypenum==3){
            if(document.getElementById("price").value.match(/^[0-9]+$/g)){
                question.score=parseFloat(document.getElementById("price").value);//分数
                if(parseFloat(document.getElementById("price").value)>10){
                    alert("金额不能超过10");
                }else if(parseFloat(document.getElementById("price").value)===0){
                    alert("金额不能为0");
                }else if(!document.getElementById("price").value.match(/^[0-9]+$/)){
                    alert("请输入有效金额");
                }else{
                    //上传提示提示框
                    $("#sendinfo").css("display","block");
                    //可以提交数据
                    $.ajax({
                        //提交数据的类型 POST GET
                        type: "post",
                        //提交的网址
                        //url: sendurl,
                        url:"https://www.pulu.com/webapi/api/puluquestion/AddPulu_question_e",
                        //提交的数据
                        data: {"atmeuserId":callerid, "pulu_question": question, "persons": persons, "imgs": imgs, "jobtypes": jobtypes, "hobbytypes": hobbytypes, "qSeePlist": sendcanseelist,"atmeIsHideName":atmeIsHideName},
                        //返回数据的格式
                        datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
                        //成功返回之后调用的函数
                        success: function (data) {
                            console.log(data);
                            if(data.Code=="TRUE"){
                                $("#sendinfo").css("display","none");
                                //location.href="questionlistjy.html";
                            }else{
                                $("#sendinfo").css("display","none");
                                alert("关键词未在文中出现");
                            };
                        },
                        error:function(d){
                            alert("发布失败，请稍后再试");
                        }
                    });
                }
            }
        }else{
            alert("经验金额不能为0");
        }
    };
};

//监听输入框
$("#csearchinput1").bind('input propertychange',function(){
    if(!$("#csearchinput1").val()){
        $("#aa").css("display","block");
        $("#a1").css("display","none");
    }
});
//取消发布
$("#donotsendbtn").click(function(){
    $(".modal_bg.modal_bg2").css("display","none");
    $(".action_menu_container2").css("display","none");
})
//键盘回车
document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode==13){
        //城市搜索
        $("#searclocation div").remove();
        searchcity(pagenum);
    }
};
//绑定输入
$('#locationsearch input').bind('input propertychange', function() {
    //城市搜索
    $("#searclocation div").remove();
    searchcity(pagenum);
});

$("#gaojibtn").click(function(){
    if($("#gaojilistbox").css("display")=="block"){
        $("#gaojilistbox").css("display","none");
        //匿名发布
        //$("#hidenamebox").css("display","none");
        //定位
        //$("#locationbox").css("display","none");
        //箭头
        $("#gaojiimg").attr("src","img/darr01.png");
    }else{
        $("#gaojilistbox").css("display","block");
        //匿名发布
        //$("#hidenamebox").css("display","block");
        //定位
        $("#locationbox").css("display","block");
        //箭头
        $("#gaojiimg").attr("src","img/uarr01.png");
    }
});